package Entities;

import java.util.ArrayList;
import Entities.Pickup;
import Entities.Stock;
import Entities.Terminal;
import digitshoplogic.DBAccessSingleton;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class Store {
	public int storeId;
	public String name;
	public String phoneNo;
	public String email;
	public String ZIP;
	public String city;
	public String address;

    public static final Store getStoreByID(int id) throws SQLException {
        Store store = new Store();

        PreparedStatement  ps;
         Connection con = DBAccessSingleton.getInstance().getConnection();
         ps = con.prepareStatement("select * from Store where Store.storeId = ?");
         ps.setInt(1, id);

        ResultSet rs = ps.executeQuery();

         while (rs.next()) {
            store.storeId = rs.getInt(1);
            store.name = rs.getString(2);
            store.phoneNo = rs.getString(3);
            store.email = rs.getString(4);
            store.ZIP = rs.getString(5);
            store.city = rs.getString(6);
            store.address = rs.getString(7);
        }
        rs.close();
        return store;
        }
     public static final void addStoreByObj(Store s) throws SQLException {

         PreparedStatement ps;
         Connection con = DBAccessSingleton.getInstance().getConnection();
         ps = con.prepareStatement("INSERT INTO store VALUES (?,?,?,?,?,?,?)");

         ps.setInt(1, s.storeId);
         ps.setString(2, s.name);
         ps.setString(3, s.phoneNo);
         ps.setString(4, s.email);
         ps.setString(5, s.ZIP);
         ps.setString(6, s.city);
         ps.setString(7, s.address);

         ps.executeUpdate();
         ps.close();
        }

 public static final void deleteStoreByID(int id) throws SQLException{

         PreparedStatement  ps;
         Connection con = DBAccessSingleton.getInstance().getConnection();
         ps = con.prepareStatement("DELETE FROM store WHERE store.storeId= ?");
	 ps.setInt(1, id);
         ps.executeUpdate();
         ps.close();
     }
  public static final void updateStoreByObj(Store s) throws SQLException{

         PreparedStatement  ps;
         Connection con = DBAccessSingleton.getInstance().getConnection();
         ps = con.prepareStatement("UPDATE store SET "
                 + "store.name = ?, "
                 + "store.phoneNo = ?, "
                 + "store.email = ?, "
                 + "store.ZIP = ?, "
                 + "store.city = ?,"
                 + "store.address = ? WHERE store.storeId = ?");

	 ps.setInt(7, s.storeId);
         ps.setString(1, s.name);
         ps.setString(2, s.phoneNo);
         ps.setString(3, s.email);
         ps.setString(4, s.ZIP);
         ps.setString(5, s.city);
         ps.setString(6, s.address);

         ps.executeUpdate();
         ps.close();

     }


    public Store(){
    }

    public String getZIP() {
        return ZIP;
    }

    public void setZIP(String ZIP) {
        this.ZIP = ZIP;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhoneNo() {
        return phoneNo;
    }

    public void setPhoneNo(String phoneNo) {
        this.phoneNo = phoneNo;
    }   

    public int getStoreId() {
        return storeId;
    }

    public void setStoreId(int storeId) {
        this.storeId = storeId;
    }

}